package com.example.service;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
public class RedisServiceImpl implements RedisService {

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public RedisTemplate getRedisTemplate() {
        return redisTemplate;
    }

    @Override
    public void set(String key, byte[] bytes) throws Exception {
        this.redisTemplate.opsForValue().set(key,bytes);
    }

    @Override
    public void set(String key, byte[] bytes, long timeout, TimeUnit unit) {
        this.redisTemplate.opsForValue().set(key,bytes,timeout,unit);
    }

    @Override
    public Object get(String key) throws Exception {
       return this.redisTemplate.opsForValue().get(key);
    }

    @Override
    public int getRandom() throws Exception {
        return 0;
    }
}
